package cn.springBoot.delegate;

import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

/** 
 * @description:  Delegate Expression 类型的
 * @param:null 
 * @author: ljx
 * @create date: 2021/9/29 
 * @version: V1.0 
 * @return:  
 */


@Component("leave_message")
public class LeaveMessageDelegate implements JavaDelegate {
    private final Logger LOGGER = Logger.getLogger(LeaveMessageDelegate.class.getName());
    @Autowired
    TaskService taskService;
    @Override
    public void execute(DelegateExecution execution) throws Exception {
       LOGGER.info("通知用户审核通过");

        LOGGER.info("设置处理人为ljx");
        List<Task> list = taskService.createTaskQuery().processInstanceId(execution.getProcessInstanceId())
                .active()
                .list();
        for (Task task:list){
            System.out.println("name:"+task.getName());
            System.out.println("id:"+task.getId());
            System.out.println("ProcessDefinitionId"+task.getProcessDefinitionId());
            System.out.println("taskDefinitionKey"+task.getTaskDefinitionKey());
            System.out.println("当前任务执行人:"+task.getAssignee());

        }
        String message = (String) execution.getVariable("starter");

        System.out.println("当前任务执行人:"+message);
        execution.setVariable("starter", "ljx");
      /*   String message = (String) execution.getVariable("message");
        LOGGER.info("message:"+message);


        //添加会签人员
        System.out.println("%%%%%%%%%%%%%%%添加会签人员%%%%%%%%%%%%%%%%%%%");
        List<String> userList = new ArrayList<>();
        userList.add("user1");
        userList.add("user2");
        userList.add("user3");
        execution.setVariable("assigneeList", userList);
        System.out.println("%%%%%%%%%%%%%%%添加结束%%%%%%%%%%%%%%%%%%%");*/
    }




}
